<table cellpadding="0" cellspacing="0">
	<tbody>
        <tr>
            <td class="leftside">
           		<?php require_once("menu.php");?>
            </td>
            <td class="rightside">
                <div class="box" style="margin-left:10px; margin-right: 10px; float:left;">
                	<div id='title_menu' class="ui-corner-top">เพิ่มบัญชีธนาคาร</div>  
                    <div class="content" style="min-height: 150px;">
                    <form action="#" method="post" enctype="multipart/form-data" <?php isset($_GET['id'])?print 'id="bank_update"':print 'id="bank_detail"';?>>
                    <?php 
					if(isset($_GET['id'])){
						$edit_sql 	= 'SELECT * FROM banks WHERE id='.$_GET['id'];
						$edit_q		= $db->select_query($edit_sql);
						$edit_bank	= $db->fetch($edit_q);
						$has		= $db->rows($edit_q);
					}
					?>
                        <table border="0" width="500">
                          <tr>
                            <td width="110" style="text-align: right"><strong>ชื่อธนาคาร: </strong></td>
                            <td width="370">
                            <?php 
								($has > 0)? print '<input type="text" name="bank_name" id="bank_name" value="'.$edit_bank['name'].'"/>':
											print '<input type="text" name="bank_name" id="bank_name" />';
							?>
                           	</td>
                          </tr>
                          <tr>
                            <td style="text-align: right"><strong>สาขา: </strong></td>
                            <td>
                            <?php 
								($has > 0)? print '<input type="text" name="branch" id="branch" value="'.$edit_bank['branch'].'"/>':
											print '<input type="text" name="branch" id="branch" />';
							?>
                          	</td>
                          </tr>
                          <tr>
                            <td style="text-align: right"><strong>ชื่อบัญชี: </strong></td>
                            <td>
                            <?php 
								($has > 0)? print '<input type="text" name="account_name" id="account_name" value="'.$edit_bank['account_name'].'"/>':
											print '<input type="text" name="account_name" id="account_name" />';
							?>
                           	</td>
                          </tr>
                          <tr>
                            <td style="text-align: right"><strong>เลขที่บัญชี: </strong></td>
                            <td>
                            <?php 
								($has > 0)? print '<input type="text" name="account_id" id="account_id" value="'.$edit_bank['account_id'].'"/>':
											print '<input type="text" name="account_id" id="account_id" />';
							?>
                          	</td>
                          </tr>
                          <tr>
                            <td style="text-align: right" valign="top"><strong>โลโก้: </strong></td>
                            <td>
                            	<div id="upload" ><span>อัพโหลดรูป</span></div><span id="status" ></span>
                                <ul id="bank_img">
                                <?php
								if($has>0){
									$img = isset($_SESSION['bank_img'])? $_SESSION['bank_img'] : $edit_bank['logo'];
									echo '<li><img src="../styles/images/bank_images/'.$img.'" alt="'.$img.'"/></li>';
								}else{								
									$pic_num = isset($_SESSION['bank_img'])? count($_SESSION['bank_img']):0;
									if($pic_num != 0){
										echo '<li><img src="../styles/images/bank_images/'.$_SESSION['bank_img'].'" alt="'.$_SESSION['bank_img'].'"/></li>';
									}
								}
								?>
                                </ul>
                            </td>
                          </tr>
                          <tr>
                            <td style="text-align: right">&nbsp;</td>
                            <td>
                            	<input type="hidden" name="bank_id" id="bank_id" value="<?php echo $_GET['id'];?>" />
                          	<?php 
								($has > 0)? print '<input type="submit" id="bank_submit" value="อัพเดท" /><span id="loading"></span>':
											print '<input type="submit" id="bank_submit" value="เพิ่มบัญชีธนาคาร" /><span id="loading"></span>';
							?>
                           	</td>
                          </tr>
                        </table>
					</form>
                    </div>
                </div>      
                <div class="box" style="margin-left:10px; margin-right: 10px; float:left;">
                	<div id='title_menu' class="ui-corner-top">Bank accounts</div>  
                    <div class="content" style="min-height: 150px;">
                    <table class="list" >
                        <thead>
                          <tr align="center">
                            <td>ลำดับ</td>
                            <td width="100">โลโก้</td>
                            <td>รายละะเอียด</td>
                            <td>แก้ไข</td>
                            <td>ลบ</td>                            
                          </tr>
                        </thead>
                        <tbody>
                        <?php
                        	$sql 	= 'SELECT `banks`.* FROM `banks` ORDER BY `banks`.`id`';
							$q 		= $db->select_query($sql);
							$count	= 1;
							while($bank = $db->fetch($q)){
						?>
                        	<tr>
                            	<td align="center"><?php echo $count++;?></td>
                                <td>
                                <p style="margin: 25px 10px 25px;"><img src="../styles/images/bank_images/<?php echo $bank['logo'];?>"  /></p>
                                </td>
                                <td>
                                <span>
                                	<p style="margin:8px 0px;"><strong>ธนาคาร:</strong> <?php echo $bank['name'];?></p>
                                	<p style="margin:8px 0px;"><strong>หมายเลขบัญชี:</strong> <?php echo $bank['account_id'];?></p>
                                    <p style="margin:8px 0px;"><strong>สาขา:</strong> <?php echo $bank['branch'];?></p>
                                    <p style="margin:8px 0px;"><strong>ชื่อบัญชี:</strong> <?php echo $bank['account_name'];?></p>
                                </span>
                                </td>
                                <td align="center">
                                	<a href="?m=bank&p=add_bank&id=<?php echo $bank['id'];?>" id="delbank" bankid="<?php echo $bank['id'];?>">
                                    	<img src="images/edit.png" align="absmiddle" title="Edit bank images" />
                                    </a>
                               	</td>
                                <td align="center">
                                	<a href="#" id="delbank" bankid="<?php echo $bank['id'];?>">
                                		<img src="images/delete.png" align="absmiddle" title="Delete bank images" />
                                    </a>
                              	</td>
                            </tr>
                        <?php
							}
						?>
                        </tbody>
                    </table>
                   	</div>
               	</div>
            </td>
        </tr>
   	</tbody>
</table>
<script type="text/javascript">
$(function(){
	var btnUpload=$('#upload');
	var status=$('#status');
	new AjaxUpload(btnUpload, {
		action: 'upload-image.php?upload_bank_img=true',
		name: 'uploadfile',
		onSubmit: function(file, ext){			
			if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
				// extension is not allowed 
				status.text('ไฟล์ที่คุณสามารถอัพโหลดได้คือ .jpg, .jpeg, .png และ .gif เท่านั้น');
				return false;
			}
			status.text('Uploading...');
		},
		onComplete: function(file, response){
			//On completion clear the status
			status.text('');
			//Add uploaded file to list
			var imgstatus = response.split(',');
			
			if(imgstatus[0]==="success"){
				$('#bank_img li').remove();
				$('<li></li>').appendTo('#bank_img').html('<img src="../styles/images/bank_images/'+imgstatus[1]+'" alt="'+imgstatus[1]+'" /><input type="hidden" name="img[]" value="'+imgstatus[1]+'"/>').addClass('success');
				count_img++;
				
			} else{
				$('<li></li>').appendTo('#bank_img').text(imgstatus[1]).addClass('error');
			}

		}
	});
});
</script>